import { Component, Vue } from "vue-property-decorator"
import { Getter, Action } from "vuex-class"
import { LoginData } from '@/views/login.interface'
import {Toast} from 'vant';
 import { Tabs } from "@/components/index"
import {LoginForm} from '@/components/tabs.interface';
import {LoginUtils} from '@/views/login/userJson';
import {setToken, TheRouter} from '@/utils/common'; // 组件

@Component({
  components:{
    Tabs
  }
})
export default class Login extends Vue {
  // Getter
  // @Getter login.author

  // Action
  // @Action GET_DATA_ASYN

  // data
  data: LoginData = {
    pageName: 'login'
  }
  loginForm:LoginForm = new LoginForm();
  login(){
    this.$axios({
      method: 'get',
      url: '/data.json'
    })
    .then((res:any)=>{
      let response:any = JSON.parse(JSON.stringify(res.data.data));
      let resMap:Map<string,string> = new Map();

      for (let i = 0; i < response.length; i++) {
        let ele = response[i];
        if(!resMap.has(ele.userName)){
          resMap.set(ele.userName,ele.password)
        }
      }
      if(this.loginForm.slectedMethod){
        if(resMap.has(this.loginForm.username!) && resMap.get(this.loginForm.username!) === this.loginForm.password ){
          Toast('登录成功')
          setToken('1234567')
          TheRouter.toHome(this);
        }else{
          Toast('账号或密码错误，请重试')
        }
      }else{

      }


    })
    // if(this.loginForm.slectedMethod){
    //   if(LoginUtils.loginByPassword(this.loginForm.username!) === this.loginForm.password){
    //
    //   }else{
    //     Toast('账号或密码错误，请重试')
    //   }
    // }else{
    //   if(LoginUtils.loginByCheckCode(this.loginForm.phone!) === this.loginForm.validcode){
    //     Toast('登录成功')
    //     setToken('1234567')
    //     TheRouter.toHome(this);
    //   }else{
    //     Toast('验证码错误')
    //   }
    // }
  }
  uploadInfo(val:LoginForm){
    this.loginForm = val;
  }
  created() {
    //
  }

  activated() {
    //
  }

  mounted() {
    //
  }
  onClickLeft() {
    window.history.go(-1)
  }
  onClickRight() {
    Toast('按钮');
  }
  // 初始化函数
  init() {
    //
  }

}
